//
//  ArticlePageViewAvatarCell.swift
//  iModern
//
//  Created by Ralf on 7/26/15.
//  Copyright (c) 2015 com.starlooking. All rights reserved.
//

import UIKit

class ArticlePageViewAvatarCell: TableViewCell
{

    @IBOutlet var avatarImageView:       UIImageView!
    @IBOutlet var aliasLabel:            UILabel!
    @IBOutlet var cityLabel:             UILabel!
    @IBOutlet var numberOfCommentsLabel: UILabel!

    @IBOutlet var lab: UILabel!
    override func awakeFromNib()
    {
        super.awakeFromNib()

        avatarImageView!.layer.cornerRadius = 25.0
        avatarImageView!.layer.masksToBounds = true
        avatarImageView!.layer.borderColor = UIColor.blackColor().CGColor
        avatarImageView!.layer.borderWidth = 1.0
        avatarImageView!.backgroundColor = UIColor.grayColor()
        initLabel()
        initLabel2()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool)
    {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    func setData(data: NSDictionary)
    {
        let article = data["article"] as! NSDictionary
        let contact = article["contact"] as! NSDictionary
        aliasLabel.text = contact["shopName"] as? String
        let imageURL = contact["shopLogoURL"] as? String
        if imageURL != nil
        {
            let url = appDelegate.parameterManager.server + "/" + imageURL!
            avatarImageView.load(url, placeholder: nil)
        }

//        cityLabel.text = contact["city"] as? String
        cityLabel.text = contact["address"] as? String

        if article["numberOfReview"] == nil
        {
            numberOfCommentsLabel.text = "0 次评价"
        }
        else
        {
            let numberOfReview = article["numberOfReview"] as! Int
            numberOfCommentsLabel.text = "\(numberOfReview) 次评价"
        }
        let rateOfPraise  = article["rateOfPraise"] as! Double
        //lab.textColor = Theme.score_color
        lab.text = "好评度: \(rateOfPraise * 100)"

    }
    
    func initLabel()
    {
        let screen = UIScreen.mainScreen().bounds
        var label      = UILabel()
        let labelFrame = CGRect(x: 0, y: 2, width: screen.size.width, height: 1)
        label = UILabel(frame: labelFrame)
        label.backgroundColor = UIColor.groupTableViewBackgroundColor()
        self.addSubview(label)
    }
    
    func initLabel2()
    {
        let screen = UIScreen.mainScreen().bounds
        var label      = UILabel()
        let labelFrame = CGRect(x: 0, y: 190*2/3, width: screen.size.width, height: 1)
        label = UILabel(frame: labelFrame)
        label.backgroundColor = UIColor.groupTableViewBackgroundColor()
        self.addSubview(label)
    }


}
